/*
 * @FilePath: \undefinedc:\Users\sxjct\.leetcode\19.删除链表的倒数第-n-个结点.cpp
 * @Brief: 
 * @Version: 1.0
 * @Date: 2021-04-26 11:22:52
 * @Author: tianyiyi
 * @Copyright: Copyright@tianyiyi
 * @LastEditors: Mr.Tian
 * @LastEditTime: 2021-04-26 11:24:21
 */
/*
 * @lc app=leetcode.cn id=19 lang=cpp
 *
 * [19] 删除链表的倒数第 N 个结点
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    int cur = 0;
    ListNode* removeNthFromEnd(ListNode* head, int n) {
        if(head == NULL)
        {
            return NULL;
        }
        head->next = removeNthFromEnd(head->next,n);
        cur++;
        if(cur == n)
        {
            return head->next;
        }
        return head;
    }
};
// @lc code=end

